package chapter27;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAdjusters;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/28 20:51
 */
public class LocalDateTimeTest {
    public static void main(String[] args) {
        LocalDateTime dateTime = LocalDateTime.now();
        System.out.println(dateTime.getDayOfWeek());

        LocalDate ld = LocalDate.now();
        LocalTime lt = LocalTime.now();
        LocalDateTime ld1 = ld.atTime(12, 10, 12);
        LocalDateTime ld2 = lt.atDate(LocalDate.of(2019, 2, 28));

        System.out.println(ld1);
        System.out.println(ld2);

        System.out.println(ZonedDateTime.now());

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        System.out.println(ld1.format(formatter));

        String str = ld2.format(formatter);
        LocalDateTime ld3 = LocalDateTime.parse(str, formatter);
        System.out.println(ld3);

        ld2 = ld2.withHour(15).withMinute(20);
        ld2 = ld2.toLocalDate().atTime(15, 20);

        ld2 = ld2.plusDays(10).plusHours(20);

        ld2 = ld2.with(ChronoField.MILLI_OF_DAY, 1000);
        System.out.println(ld2);

        ld2 = ld2.with(TemporalAdjusters.next(DayOfWeek.TUESDAY)).withHour(10);

        LocalDateTime ld4 = LocalDateTime.of(LocalDate.now().plusDays(1), LocalTime.MAX);
        System.out.println(ld4);

    }
}
